package com.wanxi.servlet.view;

import com.wanxi.model.CompanyModel;
import com.wanxi.model.NavModel;
import com.wanxi.model.ProductModel;
import com.wanxi.service.CompanyService;
import com.wanxi.service.NavService;
import com.wanxi.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

@WebServlet("/company")
public class CompanyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1.乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
//        4.调用服务逻辑层service
        CompanyService companyService = new CompanyService();
        NavService navService = new NavService();
        ProductService productService = new ProductService();
//        5.将数据存入req
        //        公司信息
        CompanyModel companyModel = companyService.getCompanyModel();
        req.setAttribute("companyModel", companyModel);
        //        导航信息
        List<NavModel> navModelList = navService.getNavModelList();
        req.setAttribute("navModelList", navModelList);

//        产品信息
        List<ProductModel> productModelList = productService.getCompanyProductModelList();
        req.setAttribute("productModelList", productModelList);
//        6.页面转发
        req.getRequestDispatcher("/jsp/company.jsp").forward(req, resp);
    }
}
